#include "../menu.h"
#include "../../user.h"
#include "../aw_sys_app.h"
#include "filenav.h"
#include "logo_dat.h" 
#include "../aw_init_display.h"


#include <sys/types.h>
#include <aw_playlist2.h>

#include "../menu.h"
#include <listop.h>
#include <app/avi/avi_sub.h>
#include "user.h"
#include "t_filelist.h"
#include "filenav.h"
#include "aw_app.h"
#include "../aw_sys_app.h"
#include "../aw_init_display.h"
#include "../fs_playlist.h"
#include "../aw_gui_app.h"
#include "LogoEvent.h"

#ifdef ENABLE_NETWORK
#include"Network_SetupEvent.h"
#include "../aw_network.h"
#include "../aw_config.h"
#include "net/iwconfig/iwlib.h"
extern INT8U menu_index_process;
extern INT8U PicInfo_Highlight1;
extern INT8U Ipaddress_Hight;
extern struct aml_iw_config aml_wireless_config;

extern INT8U Yahoo_already_connected;
extern INT8U Google_already_connected;
extern INT8U FrameChannel_already_connected;
#endif

void change_warning_message(INT8U menu_id)
{
    PHWND hwnd=AWFindWinCtrlByName("WarningBox") ;
     switch(menu_id)
     {
#ifdef ENABLE_NETWORK        
     case ID_MENU_NONE_ID_PASSWORD:
         hwnd->draw_info[1].draw_data = (INT32U)MENU_NONE_ID_PASSWORD;
         hwnd->draw_info[3].draw_data = (INT32U)0;
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;
        	
     case ID_MENU_INFO_SCANNING:
         hwnd->draw_info[1].draw_data = (INT32U)NET_SCANNING_STR;
         hwnd->draw_info[3].draw_data = (INT32U)0;
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;
     case ID_MENU_NETWORK_ENABLE:
         hwnd->draw_info[1].draw_data = (INT32U)NET_ENABLE_STR;
         hwnd->draw_info[3].draw_data = (INT32U)0;
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;	
     case ID_MENU_NETWORK_DISABLE:
         hwnd->draw_info[1].draw_data = (INT32U)NET_DISABLE_STR;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;	
     case ID_MENU_CONNECT_NETWORK:
         hwnd->draw_info[1].draw_data = (INT32U)NET_CONNECTING_STR;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break; 

     case ID_MENU_CONNECT_NETWORK_SUCCESS:	
         hwnd->draw_info[1].draw_data = (INT32U)NET_CONNECTING_SUCCESS_STR;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break; 	
     case ID_MENU_NO_WIRELESS_NETWORK:
         hwnd->draw_info[1].draw_data = (INT32U)NET_SCANNING_MESSAGE_STR1;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;	
     case ID_NET_FAILED_MESSAGE_STR1:
         hwnd->draw_info[1].draw_data = (INT32U)NET_FAILED_MESSAGE_STR1;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;	
     case ID_NET_FAILED_MESSAGE_STR2:
         hwnd->draw_info[1].draw_data = (INT32U)NET_FAILED_MESSAGE_STR2;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;	
     case ID_NET_FAILED_MESSAGE_STR3:
         hwnd->draw_info[1].draw_data = (INT32U)NET_FAILED_MESSAGE_STR3;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;	
     case ID_NET_FAILED_MESSAGE_STR4:
         hwnd->draw_info[1].draw_data = (INT32U)NET_FAILED_MESSAGE_STR4;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;	
     case ID_NET_FAILED_MESSAGE_STR5:
         hwnd->draw_info[1].draw_data = (INT32U)NET_FAILED_MESSAGE_STR5;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;	
     case ID_NET_FAILED_MESSAGE_STR6:
         hwnd->draw_info[1].draw_data = (INT32U)NET_FAILED_MESSAGE_STR6;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;			 		 		
     case ID_NET_FAILED_MESSAGE_STR7:
         hwnd->draw_info[1].draw_data = (INT32U)NET_FAILED_MESSAGE_STR7;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;	
     case ID_NET_FAILED_MESSAGE_STR8:
         hwnd->draw_info[1].draw_data = (INT32U)NET_FAILED_MESSAGE_STR8;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;					
     case ID_MENU_SECURITY_WEP:
         hwnd->draw_info[1].draw_data = (INT32U)MENU_INFO_CONNECTING;
         hwnd->draw_info[3].draw_data = (INT32U)MENU_SECURITY_WEP;	
         hwnd->draw_info[5].draw_data = (INT32U)AUTHENTICATING_STR;
         break;	
     case ID_MENU_SECURITY_WPA:
         hwnd->draw_info[1].draw_data = (INT32U)MENU_INFO_CONNECTING;
         hwnd->draw_info[3].draw_data = (INT32U)MENU_SECURITY_WPA;	
         hwnd->draw_info[5].draw_data = (INT32U)AUTHENTICATING_STR;
         break;		
     case ID_NET_AUTH_SUCCESS_STR:
         hwnd->draw_info[1].draw_data = (INT32U)MENU_INFO_CONNECTING;
         if(aml_wireless_config.security == IW_SECURITY_WEP)
         {
             hwnd->draw_info[3].draw_data = (INT32U)MENU_SECURITY_WEP;	
         }
         else if(aml_wireless_config.security == IW_SECURITY_WPA)
         {
             hwnd->draw_info[3].draw_data = (INT32U)MENU_SECURITY_WPA;	
         }
         hwnd->draw_info[5].draw_data = (INT32U)AUTHENTICATED_STR;
         break;

     case ID_MENU_INFO_CONNECTING:
         hwnd->draw_info[1].draw_data = (INT32U)MENU_INFO_CONNECTING;   		
         if(aml_wireless_config.security == IW_SECURITY_WEP)
         {
             hwnd->draw_info[3].draw_data = (INT32U)MENU_SECURITY_WEP;	
         }
         else if(aml_wireless_config.security == IW_SECURITY_WPA)
         {
             hwnd->draw_info[3].draw_data = (INT32U)MENU_SECURITY_WPA;	
         }
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;
     case ID_MENU_CONNECT__SUCCESS1:
         hwnd->draw_info[1].draw_data = (INT32U)MENU_CONNECT__SUCCESS1;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         Yahoo_already_connected=1;
         menu_index_process=ID_INTERNET_YAHOO_SETTING;
         break;

     case ID_MENU_CONNECT__SUCCESS2:
         hwnd->draw_info[1].draw_data = (INT32U)MENU_CONNECT__SUCCESS2;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         Google_already_connected=1;   
         menu_index_process=ID_INTERNET_GOOGLE_SETTING;
         break;

     case ID_MENU_CONNECT_SUCCESS_FRAMECHANNEL: 
         hwnd->draw_info[1].draw_data = (INT32U)MENU_CONNECT_SUCCESS_FRAMECHANNEL;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;

         FrameChannel_already_connected = 1;
         menu_index_process = ID_INTERNET_FRAME_CHNL_SETTING;
         break;

     case ID_MENU_DISCONNECT__SUCCESS1:
         hwnd->draw_info[1].draw_data = (INT32U)MENU_DISCONNECT__SUCCESS1;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;

     case ID_MENU_DISCONNECT__SUCCESS2:
         hwnd->draw_info[1].draw_data = (INT32U)MENU_DISCONNECT__SUCCESS2;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;		  

     case ID_MENU_DISCONNECT_SUCCESS_FRAMECHANNEL: 
         hwnd->draw_info[1].draw_data = (INT32U)MENU_DISCONNECT_SUCCESS_FRAMECHANNEL;
         hwnd->draw_info[3].draw_data = (INT32U)0;	
         hwnd->draw_info[5].draw_data = (INT32U)0;
         break;		  
    	  
     case ID_MENU_GETIPADDRESS_SUCCESS1: 	  	  
         hwnd->draw_info[1].draw_data = (INT32U)MENU_INFO_CONNECTED;

         if(!Ipaddress_Hight)
             hwnd->draw_info[5].draw_data = (INT32U)MENU_IPSETTING_DYNAMIC;
         else
             hwnd->draw_info[5].draw_data = (INT32U)MENU_IPSETTING_STATIC;	
         break;
#endif
     default:
         break;    	 	
     }
}

static INT8U  menu_current = 0;
void change_message(INT8U index)
{
	menu_current = index;
	change_warning_message(index);	
}
INT32S WinWarnMessageBoxOnKeyPress(PHWND hwnd, INT32S lpParam)
{
	INT32U *key_value = (INT32U *)lpParam; 	

	switch(*key_value){
	case UOP_PROGRAM:
	#if 0
	case UOP_4:
		GUIShowWindow("WinSetup_net_menu");
		break;
	#endif
	case UOP_SETUP:
           	
		FileListInitData() ; 
		GUIShowWindow("WinWarnMessageBox") ;       			
		break;
	case UOP_RESUME:
		GUIHideWindow("WinWarnMessageBox");
     	 //ReloadLogo(Logo_keyboard, sizeof(Logo_keyboard));
     	 #ifdef ENABLE_NETWORK
		if((menu_index_process == ID_MENU_NETWORK_ENABLE)||(menu_index_process == ID_MENU_NETWORK_DISABLE))
			GUIShowWindow("WinSetup_net_menu");
		else
	#endif		
			GUIShowWindow("Network_Setup");
		break;            
    }
    return 0 ;

}

INT32S WinWarnMessageBoxOnPaint(PHWND hwnd, INT32S lpParam)
{
	osdsettpval(0,0xf);
        return 0;
	}

INT32S WinWarnMessageBoxOnShow(PHWND hwnd, INT32S lpParam)
{
	//osdsettpval(0,0xf);
       
       return 0;
	}
	
INT32S WarningBoxOnPaint(PHWND hwnd, INT32S lpParam)
{
#ifdef ENABLE_NETWORK   
   switch(menu_index_process)
   {	
   case ID_MENU_SECURITY_WEP:
   	     hwnd->pClass->ClassProc(hwnd, WM_PAINT, lpParam) ;
             AWAsciiPrintf(290,106,aml_wireless_config.essid);
             
   	   return 1;
   case ID_MENU_SECURITY_WPA:
           hwnd->pClass->ClassProc(hwnd, WM_PAINT, lpParam) ;
           AWAsciiPrintf(290,106,aml_wireless_config.essid);
      
   	   return 1;
   	   
   case ID_NET_AUTH_SUCCESS_STR:	  		
   	
    hwnd->pClass->ClassProc(hwnd, WM_PAINT, lpParam) ;
    AWAsciiPrintf(290,106,aml_wireless_config.essid);
    
   return 1;
   
    case ID_MENU_INFO_CONNECTING:	
     hwnd->pClass->ClassProc(hwnd, WM_PAINT, lpParam) ;
    AWAsciiPrintf(290,106,  aml_wireless_config.essid); 
   return 1;	
  
   case ID_MENU_GETIPADDRESS_SUCCESS1:
    hwnd->pClass->ClassProc(hwnd, WM_PAINT, lpParam) ;
    //AWAsciiPrintf(290,106,APNAME_STR[PicInfo_Highlight1]);
    AWAsciiPrintf(290,106,  aml_wireless_config.essid); 
    
    AWAsciiPrintf(110,196,ip_config_info[5]);   // Physical address
    
    AWAsciiPrintf(110,196+30,ip_config_tittle[0]);   //IP address
    AWAsciiPrintf(290,196+30,ip_config_info[0]);
    
    AWAsciiPrintf(110,226+30,ip_config_tittle[1]);   // Mask
    AWAsciiPrintf(290,226+30,ip_config_info[1]);
    
    AWAsciiPrintf(110,256+30,ip_config_tittle[2]);  //Gateway
    AWAsciiPrintf(290,256+30,ip_config_info[2]); 
     
    AWAsciiPrintf(110,286+30,ip_config_tittle[3]);  // Dns
    AWAsciiPrintf(290,286+30,ip_config_info[3]);
    
    //AWAsciiPrintf(250,426-10,ip_config_info[4]);
    
    return 1;
    default :
    	break;
   }
    	return 0;
#endif    
	}	
	
INT32S WarningBoxOnShow(PHWND hwnd, INT32S lpParam)
{
#ifdef ENABLE_NETWORK
    change_warning_message(menu_index_process);	

  	if ((menu_index_process == ID_MENU_CONNECT__SUCCESS1)||(menu_index_process == ID_MENU_DISCONNECT__SUCCESS1))
		menu_index_process = ID_INTERNET_YAHOO_SETTING;
	else if ((menu_index_process == ID_MENU_CONNECT__SUCCESS2)||(menu_index_process == ID_MENU_DISCONNECT__SUCCESS2))
		menu_index_process = ID_INTERNET_GOOGLE_SETTING;
	else if ((menu_index_process == ID_MENU_CONNECT_SUCCESS_FRAMECHANNEL)||(menu_index_process == ID_MENU_DISCONNECT_SUCCESS_FRAMECHANNEL))
		menu_index_process = ID_INTERNET_FRAME_CHNL_SETTING;
	
#endif

    return 0;
}	
	
INT32S WarningBoxOnKeyPress(PHWND hwnd, INT32S lpParam)
{
    return 0;
}		
	

